// pages/wx_zm_personalcenter/personalcenter.js
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:{},
    clientHeight:0,
    function_selected_index: 0,
    screen_history_list:[],urlOfUserImg:"http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg",
    hasUserInfo: false,
    canIUse: wx.canIUse("button.open-type.getUserInfo")
  },
  getUserInfo(){
    if(app.globalData!=null){
      if(app.globalData.userInfo != null){
        this.setData({
          userInfo: app.globalData.userInfo,
          hasUserInfo: true
        })
      } else if (this.data.canIUse){
        app.userInfoReadyCallback = res =>{
          if(res!=null){
            this.setData({
              userInfo: res.userInfo,
              hasUserInfo: true
            })
          }
        } 
      } else {
        wx.getUserInfo({
          success: res=>{
            if(res!=null){
              this.setData({
                userInfo: res.userInfo,
                hasUserInfo: true
              })
            }
          }
        })
      }
    }
    this.setData({
      userInfo: app.globalData.userInfo
    })
    console.log(app.globalData.userInfo)
  },
  getSystemInfo: function () {
    this.setData({
      clientHeight: app.globalData.clientHeight
    })
  },
  getScreenHistory: function() {
    //获取浏览历史
    this.setData({
      screen_history_list: [{
        id: 1, img: "http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg",
        bookname: "书名",
        bookposition: "第23话 我看你骨骼惊奇，是百年难得一遇的奇才，我这有有本秘籍，你可愿意拜我为师",
      }, {
        id: 1, img: "http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg",
        bookname: "书名",
        bookposition: "第23话 我看你骨骼惊奇，是百年难得一遇的奇才，我这有有本秘籍，你可愿意拜我为师",
      }]
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getUserInfo()
    
    this.getSystemInfo()
    this.getScreenHistory()
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  getUserInfo1: function (e) {
    console.log(e)
    // app.globalData.userInfo = e.detail.userInfo
    // this.setData({
    //   userInfo: e.detail.userInfo,
    //   hasUserInfo: true
    // })
  },
  selected_function: function(e) {
    //功能视图切换
    this.setData({
      function_selected_index: e.currentTarget.dataset.index
    })
  }, onGotUserInfo: function (e) {
    console.log(e.detail.errMsg)
    console.log(e.detail.userInfo)
    console.log(e.detail.rawData)
  },
})